void StopMPTasks(void)
{
UInt32 i;
if (myTaskData != NULL)
{
for (i = 0; i < numProcessors; i++)
{
if (myTaskData[i].TaskID != NULL)
{
MPTerminateTask(myTaskData[i].TaskID, noErr);
MPWaitOnQueue(notificationQueue, NULL, NULL, NULL,
kDurationForever);
}
if (myTaskData[i].fRequestQueue != NULL)
MPDeleteQueue(myTaskData[i].RequestQueue);
if (myTaskData[i].fResultQueue != NULL)
MPDeleteQueue (myTaskData[i].ResultQueue);
}
if (notificationQueue != NULL)
{
MPDeleteQueue (notificationQueue);
notificationQueue = NULL;
}
DisposePtr((Ptr)myTaskData);
myTaskData = NULL;
}
}
The StopMPTasks function iterates through all the task data structures that were created in CreateMPTasks and checks for those with valid task IDs. It then calls the function MPTerminateTask for each valid task ID.
After making the termination call, StopMPTasks then waits for a message to appear on the notification queue indicating that the task has in fact been terminated. It does so by waiting continuously on the notification queue until the termination message arrives. It then clears the task ID and disposes of the queues allocated for the task.After terminating all the existing tasks, StopMPTasks then deletes the notification queue and disposes of the task data structures.Note
If you call MPWaitOnQueue from a cooperative task, you should specify only the kDurationImmediate wait time. You must use a while loop that continuously calls MPWaitOnQueue until the termination message appears in the notification queue. Doing so also allows you to process events that may occur between calls. For additional information, see Synchronizing and Notifying Tasks .